package com.itheima.aop;

import com.itheima.bean.Student;
import com.itheima.mapper.StudentMapper;
import com.itheima.service.impl.StudentServiceImpl;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

@Component
@Aspect
public class Advice {

    @Pointcut("execution(* com.itheima.service.impl.*.*(..))")
    public  void pt(){}

//    @Autowired
//    private StudentMapper studentMapper;
        private StudentServiceImpl mapper;




    @Around("pt()")
    public  Object around(ProceedingJoinPoint pjp){
        Object result = null;
        try {
            long time1 = System.currentTimeMillis();

            result = pjp.proceed();

            long time2 = System.currentTimeMillis();

            String name = pjp.getSignature().getName();

            System.out.println("调用了"+name+"方法用了："+(time2-time1)+"毫秒");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
//            System.out.println("发生了"+throwable+"异常");
        }
        return result;
    }

}
